<template>
  <el-dialog title="分配角色" :visible.sync="isShow" @close="closeEvent">
    <el-checkbox-group v-model="checkArr">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div>
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUser } from '@/api//user'
import { sysUserAssignPrem } from '@/api/employees.js'
export default {
  name: 'DiaLogRoles',
  data() {
    return {
      checkArr: [],
      list: [],
      isShow: false,
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    //  关闭弹框
    closeEvent() {
      this.isShow = false
    },
    //  获取所有角色列表
    async getData() {
      const res = await sysRole({
        page: 1,
        pagesize: 300
      })
      this.list = res.data.rows
      //   console.log('角色 列表', res)
    },
    //  获取员工基本详情,获得基本角色
    async getuserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      this.checkArr = res.data.roleIds || []
      console.log('当前员工基本详情', res)
    },
    //  提交修改角色
    async submit() {
      await sysUserAssignPrem({
        id: this.id,
        roleIds: this.checkArr
      })
      this.$message.success('修改成功')
      this.closeEvent()
    }
  }
}
</script>

<style></style>
